package com.huzz.util.artword;

import java.awt.*;
import java.awt.image.BufferedImage;

/**
 * @Name
 * @Description 描述
 * @Author 童年的纸飞机
 * @Since 2023-08-2023/8/3 09:48
 */
public class ArtWordUtil {
    private static final int WIDTH = 100;
    private static final int HEIGHT = 30;
    private static final int FONT_SIZE = 24;


    /**
     * 生成艺术字
     * @param value 输出值
     * @param paddingCharacter 填充字符
     * @param width
     * @param height
     */
    public static void printArtWord(String value, String paddingCharacter, int width, int height, int fontSize) {

        // BufferedImage image = ImageIO.read(new File("/users/zhujiajun/ascii-art.png"));
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics g = image.getGraphics();
        g.setFont(new Font("SansSerif", Font.BOLD, fontSize));

        Graphics2D graphics = (Graphics2D) g;
        graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        graphics.drawString(value, 5, 20);

        //save this image
        // ImageIO.write(image, "png", new File("/users/zhujiajun/ascii-art.png"));

        for (int y = 0; y < height; y++) {
            StringBuilder sb = new StringBuilder();
            for (int x = 0; x < width; x++) {
                sb.append(image.getRGB(x, y) == -16777216 ? " " : paddingCharacter);
            }

            if (sb.toString().trim().isEmpty()) {
                continue;
            }

            System.out.println(sb);
        }
    }

    /**
     * 生成艺术字
     * @param value 输出值
     */
    public static void printArtWord(String value) {
        printArtWord(value, ArtPdCharacter.SOLID_SQUARE, WIDTH, HEIGHT, FONT_SIZE);
    }

    /**
     * 生成艺术字
     * @param value 输出值
     * @param fontSize
     */
    public static void printArtWord(String value, int fontSize) {
        printArtWord(value, ArtPdCharacter.SOLID_SQUARE, WIDTH, HEIGHT, fontSize);
    }

    /**
     * 生成艺术字
     * @param value 输出值
     * @param paddingCharacter 填充字符
     */
    public static void printArtWord(String value, String paddingCharacter) {
        printArtWord(value, paddingCharacter, WIDTH, HEIGHT, FONT_SIZE);
    }

    /**
     * 生成艺术字
     * @param value 输出值
     * @param paddingCharacter 填充字符
     */
    public static void printArtWord(String value, String paddingCharacter, int fontSize) {
        printArtWord(value, paddingCharacter, WIDTH, HEIGHT, fontSize);
    }
}
